package untity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class ChatRoom implements Serializable {
    private String id;
    private int userId1;
    private int userId2;
    private List<Chatmessage> oldMessage=new ArrayList<Chatmessage>();
    private List<Chatmessage> newMessage=new ArrayList<Chatmessage>();
    private int num=0;

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public int getUserId1() {
        return userId1;
    }

    public void setUserId1(int userId1) {
        this.userId1 = userId1;
    }

    public int getUserId2() {
        return userId2;
    }

    public void setUserId2(int userId2) {
        this.userId2 = userId2;
    }

    public List<Chatmessage> getOldMessage() {
        return oldMessage;
    }


    public List<Chatmessage> getNewMessage() {
        return newMessage;
    }


    public List<Chatmessage> getmessage(int id){
        List<Chatmessage> list=new ArrayList<Chatmessage>();
        for ( Chatmessage message: this.newMessage) {
            if(message.getUserId()!=id){
                System.out.println("===========");
                list.add(message);
                System.out.println(message);
//                this.newMessage.remove(message);
                this.oldMessage.add(message);
            }
        }

        for (Chatmessage c: list) {
            this.newMessage.remove(c);
        }
        if (list.isEmpty()){
            System.out.println("为空");
            return null;
        }else {
//            System.out.println(list.get(0));
            return list;
        }

    }

    public void putmessage(Chatmessage chatmessage){
        newMessage.add(chatmessage);
    }
}
